/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bbstone.pisces.comm.gui;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JTextField;

/**
 *
 * @author liguifa
 */
public class DirChooser extends javax.swing.JFrame {

    private JTextField resultDir;
    private int val;
    /**
     * Creates new form DirChooser
     */
    public DirChooser() {
        initComponents();
    }
    
    public DirChooser(JTextField resultDir) {
        initComponents();
        this.resultDir = resultDir;
    }
    
    public void setVal(int val) {
    	this.val = val;
    }
    
    public JFileChooser getDirChooser() {
    	return this.dirChooser;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dirChooser = new javax.swing.JFileChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        dirChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
        dirChooser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dirChooserActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(dirChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(dirChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void dirChooserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dirChooserActionPerformed

    	if (val == JFileChooser.APPROVE_OPTION) {
    		File selectedFile = this.dirChooser.getSelectedFile();
    		if (selectedFile != null) {
    			this.resultDir.setText(selectedFile.toString());
    		}
    	}
        this.setVisible(false);
    }//GEN-LAST:event_dirChooserActionPerformed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser dirChooser;
    // End of variables declaration//GEN-END:variables
}
